import Mock from "mockjs";

// Mock.mock用来造数据
let { data } = Mock.mock({
  // 20条数据
  "data|10-20": [
    {
      "proid|+1": 1,
      proname: "@ctitle(10)",
      img1: "@Image('100x100','@color','产品图片')",
      "category|1": ["手机", "照相机", "电视机"],
      "originprice|30-5000": 30,
      "issale|1": [0, 1],
    },
  ],
});

// 还可以编写接口
Mock.mock("/admin/pro/list", "get", () => {
  return {
    code: "200",
    message: "请求成功",
    data: data,
  };
});

Mock.mock("/admin/pro/del", "post", (option) => {
  // option.body表示前端传过来的参数对象
  const { proid } = JSON.parse(option.body);
  data = data.filter((item: any) => item.proid !== proid);

  return {
    code: "200",
    message: "删除成功",
  };
});
